package net.huashitong.supervision.task.dao;

import com.sirdc.modules.core.dao.GenericQuery;
import com.sirdc.modules.core.dao.StringDao;
import com.sirdc.modules.utils.StringUtils;
import net.huashitong.supervision.task.entity.AppLoginLog;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @author ling
 * @date: 2020/2/4
 * @time: 11:10
 * @version: 1.0
 * @Description:
 */
@Repository
public class AppLoginLogDao extends StringDao<AppLoginLog> {

    public List<AppLoginLog> queryList(AppLoginLog loginLog){
        GenericQuery obj = createQuery("obj");
        if (StringUtils.isNotBlank(loginLog.getUserName())){
            obj.append(" and userName like:userName").setParam("userName",StringUtils.getLikewords(loginLog.getUserName()));
        }
        if (StringUtils.isNotBlank(loginLog.getDeptId())){
            obj.append(" and deptId =:deptId").setParam("deptId",loginLog.getDeptId());
        }
        return obj.listResult();
    }

    /**
     * 当前用户
     * @param sysId
     * @return
     */
    public List<AppLoginLog> getByUserId(String sysId,String date) {
        GenericQuery obj = createQuery("obj");
        obj.append(" and userId =:userId").setParam("userId",sysId);
        if (StringUtils.isNotBlank(date)){
            obj.append(" and createDate >=:createDate").setParam("createDate",date);
        }
        return obj.listResult();
    }
}
